﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TamGiac
{
    class TamGiac
    {
        private Diem _diemA;
        internal Diem DiemA
        {
            get { return _diemA; }
            set { _diemA = value; }
        }

        private Diem _diemB;
        internal Diem DiemB
        {
            get { return _diemB; }
            set { _diemB = value; }
        }

        private Diem _diemC;
        internal Diem DiemC
        {
            get { return _diemC; }
            set { _diemC = value; }
        }

        private double _CanhA;
        protected double CanhA
        {
            get { return _CanhA; }
            set { _CanhA = value; }
        }

        private double _CanhB;
        protected double CanhB
        {
            get { return _CanhB; }
            set { _CanhB = value; }
        }

        private double _CanhC;
        protected double CanhC
        {
            get { return _CanhC; }
            set { _CanhC = value; }
        }

        public TamGiac()
        {
            _diemA = null;
            _diemB = null;
            _diemC = null;  
        }

        public TamGiac(Diem diemA, Diem diemB, Diem diemC)
        {
            _diemA = diemA;
            _diemB = diemB;
            _diemC = diemC;

            CanhA = diemA.KhoangCach(diemB);
            CanhB = diemB.KhoangCach(diemC);
            CanhC = diemC.KhoangCach(diemA);
        }
        
        public bool KiemTraTamGiac()
        {
            // False: Không phải tam giác
            // True: Là tam giác
            // Truyền vào 3 tham số là chiều dài 3 cạnh (kiểu số thực)

            if (CanhA <= 0 || CanhB <= 0 || CanhC <= 0)
                return false;

            if (CanhA + CanhB > CanhC && CanhA + CanhC > CanhB && CanhB + CanhC > CanhA)
                return true;

            return false;
        }

        public double Chuvi()
        {
            // tinh 3 canh
            return CanhA + CanhB + CanhC;
        }

        public double Dientich()
        {
            double p = this.Chuvi() / 2;
            return (Math.Sqrt(p * (p - CanhA) * (p - CanhB) * (p - CanhC)));


        }
    }
}
